<?php

/**
 * @author  PVer
 * @date    2018-5-7 11:14:17
 * @version V1.0
 * @desc    
 */

namespace app\portal\controller;

use cmf\controller\AdminBaseController;
use think\Validate;
use app\user\model\UserModel;

class DlyController extends AdminBaseController {

//    public function index() {
//        return $this->fetch();
//    }

    public function dly() {
        return $this->fetch();
    }

    public function loginPost() {
        if ($this->request->isPost()) {
            $validate = new Validate([
                'username' => 'require',
                'password' => 'require|min:6|max:32',
            ]);
            $validate->message([
                'username.require' => '用户名不能为空',
                'password.require' => '密码不能为空',
            ]);
            $data = $this->request->post();
            if (!$validate->check($data)) {
                $this->error($validate->getError());
            }
            $userModel = new UserModel();
            $user['user_pass'] = $data['password'];
            $user['mobile'] = $data['username'];
            $log = $userModel->doMobile($user);
            $session_login_http_referer = session('login_http_referer');
            $redirect = empty($session_login_http_referer) ? $this->request->root() : $session_login_http_referer;
            switch ($log) {
                case 0:
                    cmf_user_action('login');
                    $this->success(lang('LOGIN_SUCCESS'), $redirect);
                    return $this->fetch(':index');
                    break;
                case 1:
                    $this->error(lang('PASSWORD_NOT_RIGHT'));
                    return $this->fetch(':dly');
                    break;
                case 2:
                    $this->error('账户不存在');
                    return $this->fetch(':dly');
                    break;
                case 3:
                    $this->error('账号被禁止访问系统');
                    return $this->fetch(':dly');
                    break;
                default :
                    $this->error('未受理的请求');
                    return $this->fetch(':dly');
            }
        } else {
            $this->error("请求错误");
            return $this->fetch(':dly');
        }
    }

}
